package net.liteheaven.xblib.widget.Toast;

import android.content.Context;
import android.view.View;

import net.liteheaven.xblib.common.java.ReflectUtil;

public class ToastFactory {

    private static Class<?> ToastList [] = {
            SmartToast.class,
            MiuiToast.class
    };

    public static SmartToast makeText(Context context, String text, int duration, int type) {

        if (type < 0){
            type = 0;
        }
        if (type >= ToastList.length){
            type = ToastList.length;
        }

        Class<?> t = ToastList[type];
        Class<?> argsClass [] = {
                Context.class,
                String.class,
                int.class
        };
        Object args [] = {
                context,
                text,
                duration
        };
        SmartToast st = (SmartToast) ReflectUtil.invokeConstructor(t, argsClass, args);
        return st;
    }

    public static SmartToast makeText(Context context, View v, int duration, int type) {

        if (type < 0){
            type = 0;
        }
        if (type >= ToastList.length){
            type = ToastList.length;
        }

        Class<?> t = ToastList[type];
        Class<?> argsClass [] = {
                Context.class,
                View.class,
                int.class
        };
        Object args [] = {
                context,
                v,
                duration
        };
        SmartToast st = (SmartToast) ReflectUtil.invokeConstructor(t, argsClass, args);
        return st;
    }

    public static SmartToast makeText(Context context, int resId , int duration, int type) {

        if (type < 0){
            type = 0;
        }
        if (type >= ToastList.length){
            type = ToastList.length;
        }

        String content = context.getString(resId);

        Class<?> t = ToastList[type];
        Class<?> argsClass [] = {
                Context.class,
                String.class,
                int.class
        };
        Object args [] = {
                context,
                content,
                duration
        };
        SmartToast st = (SmartToast) ReflectUtil.invokeConstructor(t, argsClass, args);
        return st;
    }
}
